/**
 * @Title: YuYueFeign.java
 * @Description: 用一句话描述该文件做什么
 * @author zhangxin
 * @date 2019年3月26日
 */
package com.fortune.rainshine.system.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fortune.rainshine.common.BaseController;
import com.fortune.rainshine.common.utils.StringUtil;
import com.fortune.rainshine.system.service.YuYueService;
import com.fortune.rainshinecommon.base.MsgModel;
import com.fortune.rainshinecommon.base.ParmsModel;
import com.fortune.rainshinecommon.enums.ResultCode;
import com.fortune.rainshinecommon.model.system.YuYueModel;

/**
 * @ClassName: YuYueFeign
 * @Description: 这里用一句话描述这个类的作用
 * @author zhangxin
 * @date 2019年3月26日
 */
@Controller
@RequestMapping("/system/yuyue")
public class YuYueController extends BaseController {
	
	@Autowired
    private YuYueService service;
	
    @RequiresPermissions("yuyue:view")
    @RequestMapping()
    public String yuyue() {
        return "appointment/appointment.html";
    }
    
    /**
     * @Title: list
     * @Description: 预约列表
     * @author zhangxin
     * @date 2019年3月26日
     */
    @RequiresPermissions("yuyue:view")
    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MsgModel list(Integer page, Integer limit, String searchKey, String searchValue) {
    	 if (page == null) {
             page = 0;
             limit = 0;
         }
         if (StringUtil.isBlank(searchValue)) {
             searchKey = null;
         }
         if(StringUtil.isNotBlank(searchKey) && searchKey.equals("deal_with")) {
        	 if(searchValue.equals("已联系")) {
        		 searchValue = "1";
        	 }else if(searchValue.equals("未联系")) {
        		 searchValue = "0";
        	 }else {
        		 return new MsgModel("筛选条件值应为'已联系'或'未联系'", ResultCode.FAILURE);
        	 }
         }
         ParmsModel parm = new ParmsModel(page,limit,searchKey,searchValue);
         
         MsgModel ms = service.list(parm);
         return ms;
    }
    
    /**
     * @Title: updateState
     * @Description: 更新处理状态
     * @author zhangxin
     * @phone 17561783855
     * @date 2019年3月28日
     */
    @RequiresPermissions("yuyue:updateState")
    @ResponseBody
    @RequestMapping("/updateState")
    public MsgModel updateState(@RequestBody YuYueModel yuyue) {
        if (service.updateState(yuyue)) {
            return new MsgModel(ResultCode.SUCCESS);
        } else {
            return new MsgModel(ResultCode.FAILURE);
        }
    }
    
    /**
     * @Title: delete
     * @Description: 删除预约
     * @author zhangxin
     * @phone 17561783855
     * @date 2019年3月28日
     */
    @RequiresPermissions("yuyeu:delete")
    @ResponseBody
    @RequestMapping("/delete")
    public MsgModel delete(@RequestBody YuYueModel yuyue) {
        if (service.delete(yuyue)) {
        	return new MsgModel(ResultCode.SUCCESS);
        }
        return new MsgModel(ResultCode.FAILURE);
    }
    
}
